<?php
/**
 * 个人信息
 * @author zzdboy
 *
 */
class ManageAction extends AdminAction {
	
	public function index() {
		$this->display ();
	}
	
	/**
	 * 修改个人信息
	 */
	public function editinfo() {
		if ($this->isPost ()) {
			$Admin = D ( "Admin" );
			
			$data ['realname'] = $this->_post ( "realname" );
			if (empty ( $data ['realname'] )) {
				$this->error ( "真实姓名不能为空!" );
			}
			$data ['email'] = $this->_post ( "email" );
			if (empty ( $data ['email'] )) {
				$this->error ( "电子邮件不能为空!" );
			}
			$data ['lang'] = $this->_post ( "lang" );
			if (empty ( $data ['lang'] )) {
				$this->error ( "请选择语言!" );
			}
			import ( "ORG.Util.Session" );
			$uid = Session::get ( "admin_uid" );
			$return = $Admin->where ( "uid={$uid}" )->data ( $data )->save ();
			
			if ($return) {
				$this->success ( "修改个人信息成功!", "/manage/editinfo/" );
			} else {
				$this->error ( "修改个人信息失败!" );
			}
		
		} else {
			$this->display ();
		}
	}
	
	/**
	 * 修改密码
	 */
	public function editpwd() {
		if ($this->isPost ()) {
			$Admin = D ( "Admin" );
			
			$old_password = $this->_post ( "old_password" );
			if (empty ( $old_password )) {
				$this->error ( "旧密码不能为空!" );
			}
			$new_password = $this->_post ( "new_password" );
			if (empty ( $new_password )) {
				$this->error ( "新密码不能为空!" );
			}
			$new_pwdconfirm = $this->_post ( "new_pwdconfirm" );
			if (empty ( $new_pwdconfirm )) {
				$this->error ( "请在输入一次新密码!" );
			}
			if ($new_password != $new_pwdconfirm) {
				$this->error ( "两次输入的密码不一样，请重新输入!" );
			}
			
			import ( "ORG.Util.Session" );
			$uid = Session::get ( "admin_uid" );
			$AdminInfo = $Admin->find ( $uid );
			if (strtolower ( md5 ( $old_password ) ) != strtolower ( $AdminInfo [password] )) {
				$this->error ( "旧密码输入错误!" );
			}
			
			$data ['password'] = md5 ( $this->_post ( "new_password" ) );
			$return = $Admin->where ( "uid={$uid}" )->data ( $data )->save ();
			
			if ($return) {
				$this->success ( "修改密码成功!", "/manage/editpwd/" );
			} else {
				$this->error ( "修改密码失败!" );
			}
		} else {
			$this->display ();
		}
	}
}
?>